package com.example.activity;

import android.content.ComponentName;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Parcelable;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class MetaDataActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_meta_data);
        // 获取当前包管理器
        PackageManager packageManager = getPackageManager();
        // 获取当前activity的信息对象，从信息中获取bundle
        Bundle bundle;
        try {
            ActivityInfo activityInfo = packageManager.getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
            bundle = activityInfo.metaData;
        } catch (PackageManager.NameNotFoundException e) {
            throw new RuntimeException(e);
        }

        // 通过getxxx()方法来获取数据
        TextView textView = findViewById(R.id.tv_meta_data);
        textView.setText(bundle.getString("meta_data"));
    }
}
